<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of admin_report
 * 
 * @author Joydeb Choudhury (mcajoydeb@gmail.com)
 */
class Reports extends CI_Controller {

    //put your code here


    function Reports() {
        parent :: __construct();
        $this->template->set_theme('admin');
        $this->template->set_layout('admin_layout');
        $this->load->library('pagination');
        $this->load->model('counter_model');
        $this->load->model('member_model');
        $this->load->model('reviews_model');
        $this->load->model('management_model');
        $this->load->model('requirement_model');
        $this->load->model('news_model');
        $this->commoncall->check_admin_login();
    }
//-------- All Member (Acitive and Inactive) Report (26.9.12)-------------
    function member() {
        $offset = 0 + $this->uri->segment(4);
        $config['base_url'] = base_url() . 'admin/reports/member/';
        $total = $this->counter_model->count_all_record('member_master');
        $perpage = 10;
        $config['per_page'] = $perpage;
        $config['total_rows'] = $total;
        $config['uri_segment'] = '4';
        $data['member'] = $this->member_model->get_members($offset, $perpage);
        $this->pagination->initialize($config);
        $this->template->title('Dashboard', $this->settings_model->get_setting('webtitle'))
                ->set_partial('admin_header', 'header/admin_header')
                ->set_partial('admin_left_menu', 'sidebar/admin_left_menu')
                ->build('pages/admin_member_report', $data);
    }
//-------- All Reviews(Acitive and Inactive) Report (26.9.12)-------------
    function reviews() {
        $offset = 0 + $this->uri->segment(4);
        $config['base_url'] = base_url() . 'admin/reports/reviews';
        $total = $this->counter_model->count_all_record('reviews');
        $perpage = 10;
        $config['per_page'] = $perpage;
        $config['total_rows'] = $total;
        $config['uri_segment'] = '4';
        $this->pagination->initialize($config);
        $data['review'] = $this->reviews_model->get_reviews(NULL, $perpage, $offset);
        $this->template->title('Dashboard', $this->settings_model->get_setting('webtitle'))
                ->set_partial('admin_header', 'header/admin_header')
                ->set_partial('admin_left_menu', 'sidebar/admin_left_menu')
                ->build('pages/admin_review_report', $data);
    }
//-------- All Post Requirment (Acitive and Inactive) Report (26.9.12)-------------
    function post_requirement() {
        $per_page = 10;
        $offset = 0 + $this->uri->segment(4);
        $config['base_url'] = base_url() . 'admin/reports/post_requirment';
        $config['total_rows'] = $this->counter_model->count_all_record('post_requirement');
        $config['uri_segment'] = '4';
        $config['per_page'] = $per_page;
        $data['requirements'] = $this->requirement_model->get_requirements($type = 'CAR', $status = NULL, $per_page, $offset, $mode = 'DESC');
        $this->pagination->initialize($config);
        $this->template->title('Dashboard', $this->settings_model->get_setting('webtitle'))
                ->set_partial('admin_header', 'header/admin_header')
                ->set_partial('admin_left_menu', 'sidebar/admin_left_menu')
                ->build('pages/admin_post_requirement_report', $data);
    }
//-------- All News Report (Acitive and Inactive) (26.9.12)-------------
    function news() {
        $offset = 0 + $this->uri->segment(4);
        $config['base_url'] = base_url() . 'admin/reports/news';
        $total = $this->counter_model->count_all_record('news');
        $perpage = 5;
        $config['per_page'] = $perpage;
        $config['total_rows'] = $total;
        $config['uri_segment'] = '4';
        $data['news'] = $this->news_model->get_all_news($perpage, $offset);
        $this->pagination->initialize($config);
        $this->template->title('Dashboard', $this->settings_model->get_setting('webtitle'))
                ->set_partial('admin_header', 'header/admin_header')
                ->set_partial('admin_left_menu', 'sidebar/admin_left_menu')
                ->build('pages/admin_news_report', $data);
    }
//-------- Change Member status in Report (26.9.12)-------------
    function change_member_status($id, $status) {
        $this->member_model->change_status($id, $status);
        redirect('admin/reports/member');
    }
//-------- Change review status in Report (26.9.12)-------------
    function change_review_status($id, $status) {
        $this->review_model->change_status($id, $status);
        redirect('admin/reports/reviews');
    }
//-------- Change requirment status in Report (26.9.12)-------------
    function change_requirement_status($id, $status) {
        $this->requirement_model->change_status($id, $status);
        redirect('admin/reports/post_requirement');
    }
//-------- Delete news status in Report (26.9.12)-------------
    function delete_news($id) {

        if ($id) {
            $sql = "delete from news where id=$id";
            $this->db->query($sql);
            redirect('admin/reports/news/');
        }
    }
}
?>
